package cn.anc.aonicardv.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import cn.anc.aonicardv.R;
import cn.anc.aonicardv.util.UIUtil;

/**
 * Created by yangdai on 2017/5/19.
 */

public class RecorderEditPopWindow extends PopupWindow {

    private Context c;
    public TextView downloadTv;
    public TextView deleteTv,deleteTvText;
    public TextView shareTv,shareTvText;
    public LinearLayout downloadRl;
    public LinearLayout deleteRl;
    public LinearLayout shareRl;
    private boolean showShare = true;

    public RecorderEditPopWindow(int width, int height, Context c,boolean showShare) {
        super(width, height);
        this.c = c;
        this.showShare = showShare;
        init();
    }

    private void init() {
        View v = LayoutInflater.from(c).inflate(R.layout.pop_recorder_edit, null);
        setContentView(v);
        setAnimationStyle(R.style.EditPopWindowStyle);
        downloadTv = (TextView) v.findViewById(R.id.tv_download);
        deleteTv = (TextView) v.findViewById(R.id.tv_delete);
        deleteTvText = (TextView) v.findViewById(R.id.tv_delete_text);

        shareTv = (TextView) v.findViewById(R.id.tv_share);
        shareTvText = (TextView) v.findViewById(R.id.tv_share_text);


        downloadRl =  v.findViewById(R.id.rl_download);
        deleteRl = v.findViewById(R.id.rl_delete);
        shareRl =  v.findViewById(R.id.rl_share);
        shareRl.setVisibility(showShare?View.VISIBLE:View.GONE);
        downloadRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onEditListener == null)
                    return;
                onEditListener.download();
            }
        });

        deleteRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onEditListener == null)
                    return;
                onEditListener.delete();
            }
        });
        shareRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onEditListener == null)
                    return;
                onEditListener.share();
            }
        });
    }

    private OnEditListener onEditListener;

    public void setOnEditListenr(OnEditListener onEditListenr) {
        if (onEditListenr == null)
            return;
        this.onEditListener = onEditListenr;
    }


    public void setEnable(boolean enable) {
        if (enable) {
            downloadTv.setBackgroundResource(R.mipmap.download_enable_true);
            deleteTv.setBackgroundResource(R.mipmap.delete_enable_true);
            deleteTvText.setTextColor(UIUtil.getColor(R.color.recorder_edit_text_s));
            shareTv.setBackgroundResource(R.mipmap.remove_enable_true);
            shareTvText.setTextColor(UIUtil.getColor(R.color.recorder_edit_text_s));
        } else {
            downloadTv.setBackgroundResource(R.mipmap.download_enable_false);
            deleteTv.setBackgroundResource(R.mipmap.delete_enable_false);
            deleteTvText.setTextColor(UIUtil.getColor(R.color.recorder_edit_text_n));
            shareTv.setBackgroundResource(R.mipmap.remove_enable_false);
            shareTvText.setTextColor(UIUtil.getColor(R.color.recorder_edit_text_n));
        }
        shareRl.setEnabled(enable);
        downloadRl.setEnabled(enable);
        deleteRl.setEnabled(enable);
    }


    public void setShareEnable(boolean enable) {
        if (enable) {
            shareTv.setBackgroundResource(R.mipmap.remove_enable_true);

        } else {
            shareTv.setBackgroundResource(R.mipmap.remove_enable_false);

        }
        shareRl.setEnabled(enable);
    }
    public void setShareVisible(boolean visible) {
        if (visible) {
            shareRl.setVisibility(View.VISIBLE);
        } else {
            shareRl.setVisibility(View.GONE);
        }
    }

    public interface OnEditListener {

        void delete();

        void download();

        void cancel();

        void share();

    }


}
